<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="oneroom.admin.board.boardModel" %>
<%@ page import="oneroom.admin.code.codeModel" %>
<jsp:useBean id="dao" scope="page" class="oneroom.admin.board.boardDao" />
<jsp:useBean id="codeDao" scope="page" class="oneroom.admin.code.codeDao" />
<%
	List codeList = codeDao.getDtlList("200");
	/*
	페이징 관련 
	*/
	String pageName = "list.jsp";
	String viewName = "view.jsp";
	int     giSelectPage  	= Integer.parseInt(request.getParameter("txtSelectPage") == null ? "0" :request.getParameter("txtSelectPage"));			//현재 선택된 페이지 저장
	int     giSelectBlock 	= Integer.parseInt(request.getParameter("txtSelectBlock") == null ? "0" :request.getParameter("txtSelectBlock"));			//현재 선택된 블락페이지 저장
	String searchGubn  = request.getParameter("searchGubn") == null ? "" : request.getParameter("searchGubn");
	String searchValue = request.getParameter("searchValue") == null ? "" : request.getParameter("searchValue");
	String searchBoard = request.getParameter("searchBoard") == null ? "" : request.getParameter("searchBoard");
	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 10;  			// 한페이지에 나타내고자 하는 List수
	int     giBlockSize   	= 10;   		// Block의 수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giStartPos    	= 0;   			// 시작 List 위치
	int     giTotPage     	= 0;   			// 총 Page수
	int     giTotBlock    	= 0;   			// 총 Block수
	//  넘겨온 값 받기(List페이지 관련)...
	if ( giSelectPage  >  0 ) { 			// 선택된 Page값이 있을경우....     
		giCurPage  = giSelectPage;   	// 현재Page = 선택된Page 
		giCurBlock = giSelectBlock;  	// 블락page = 선택된 블락 page
	}
	//쿼리를 돌려서 가지고 오는 값
	List list = dao.getList(searchBoard,searchGubn,searchValue, giSelectPage, giPageSize);
	if (list.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = dao.getCount(searchBoard,searchGubn,searchValue); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
		giTotBlock = giTotPage / giBlockSize;
		if (giTotPage % giBlockSize != 0) {
			giTotBlock = giTotBlock + 1;		// 총 Block수를 구한다...
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>원룸 - 게시판 관리</title>
<script type="text/javascript" src="/admin/js/default.js"></script>
<link href="/admin/css/default.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]><link rel="stylesheet" href="/admin/css/forie6.css" type="text/css" /><![endif]-->
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	$('#wrtBtn').click(function() {
		window.location.href="write.jsp";
	});
});

function goView(data_id){
	document.frmView.data_id.value = data_id;
	document.frmView.submit();
}

//-->
</script>
</head>
<body>
<div id="bodywrap">
	<div class="all-wrap">
		<%@ include file="/admin/common/top.jsp" %>
		<div id="right-wrap">
			<%@ include file="/admin/common/navi.jsp" %>
			<!--Contents Start-->
			<div id="content">
				<form action="list.jsp" name="frm" id="frm" method="post">
				<!-- 타이틀 및 전체 갯수 검색 시작 -->
				<div class="path">
					<span>home</span> &gt;  게시판 관리
				</div>
				<h4>게시판 관리</h4>
				<p class="sub-text">게시판 관리 하실 수 있습니다.</p>
				<div class="list-search">
						<fieldset>
						<legend>게시판 종류</legend>
						<p>
						게시판 종류  
						<label for="searchText">검색</label>
						<select id="searchBoard" class="selectMain" name="searchBoard" style="width:100px;">
							<option value="all" >전체</option>
							<%
								for(int i = 0; i<codeList.size(); i++){
									codeModel mode = (codeModel)codeList.get(i);
							%>
								<option value="<%=mode.getCode() %>" <%if(searchBoard.equals(mode.getCode())){out.print(" selected='selected' ");} %>><%=mode.getCodename() %></option>
							<%
								}
							%>
						</select>
						<input type="submit" value="검색" class="btn-black"  />
						</p>
      					<p>&nbsp;</p>						
						</fieldset>
				</div>
				<!-- 타이틀 및 전체 갯수 검색  끝-->
				<p class="board-total">전체 게시물수 <span><%=giRecordcnt %></span></p>
				<!-- 실제적인 리스트 시작 -->
				<fieldset>
					<table class="list-normal" cellpadding="0" cellspacing="0" summary="게시판 관리" >
					<caption>게시판 관리 </caption>
					<col width="50px" />
					<col width="100px" />
					<col/>
					<col width="80px" />   
					<col width="80px" /> 
					<thead>
						<tr>
							<th scope="col" >No</th>
							<th scope="col" >구분</th>
							<th scope="col" >제목</th>
							<th scope="col" >등록자</th>
							<th scope="col" >등록일</th>
						</tr>
					</thead>
					<tbody>
					<%
						if(list != null && list.size() > 0){
							giCount  = 1;
							giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
							giStartPos = ((giCurPage - 1) * giPageSize) + 1;
							for(int i = 0; i<list.size(); i++){
								boardModel model = (boardModel)list.get(i);
					%>
					<tr>
						<td><%=giRecordcnt %></td>
						<td>
							<%
								for(int j = 0; j<codeList.size(); j++){
									codeModel codemode = (codeModel)codeList.get(j);
							%>
								<%if(model.getBoard_kind().equals(codemode.getCode())){out.print(codemode.getCodename());} %>
							<%
								}
							%>
						</td>
						<td><a href="javascript:goView('<%=model.getData_id() %>')"><%=model.getTitle() %></a></td>
						<td><%=model.getReg_id() %></td>
						<td><%=model.getReg_date() %></td>
					</tr>
					<%
								giCount = giCount + 1;
								giRecordcnt = giRecordcnt - 1;
							}
						}else{
					%>
					<tr><td colspan="5">등록된 내용이 없습니다.</td></tr>
					<%
						}
					%>
					</tbody>
					</table>
					<!-- 버튼 시작 -->
					<div class="btn-all-align2">
						<span class="btn-align"><input type="button" value="등록" class="btn-bg-gray" id="wrtBtn" /></span>
					</div>
					<!-- 버튼 끝 -->
				</fieldset>
				<!-- 실제적인 리스트 끝 -->
				<!-- 페이징 시작 -->
				<div class="page-num">
					<%@ include file="/admin/common/pages.jsp" %>
					<!-- 검색 시작 -->
					<div class="list-search">
							<fieldset>
								<legend>매물 검색</legend>
								<label for="searchText">검색조건</label>
								<select name="searchGubn" style="width:50px;">
									<option value="all" <%if(searchGubn.equals("all")){out.print(" selected='selected'");} %>>전체</option>
									<option value="title" <%if(searchGubn.equals("title")){out.print(" selected='selected'");} %>>제목</option>
									<option value="content" <%if(searchGubn.equals("content")){out.print(" selected='selected'");} %>>내용</option>
								</select>
								<input type="text" name="searchValue" style="width:100px;" value="<%=searchValue %>" />
								<input type="submit" value="검색" class="btn-black"  />
							</fieldset>
					</div>
					<!-- 검색 끝  -->
				</div>
				<!-- 페이징 끝 -->
				</form>
			</div>
			<!--Contents End-->
		</div>
	</div>
</div>
<form action="view.jsp" method="post" name="frmView" >
<input type="hidden" name="searchGubn" value="<%=searchGubn %>"/>
<input type="hidden" name="searchValue" value="<%=searchValue %>"/>
<input type="hidden" name="txtSelectPage" value="<%=giSelectPage %>"/>
<input type="hidden" name="txtSelectBlock" value="<%=giSelectBlock %>"/>
<input type="hidden" name="searchBoard" value="<%=searchBoard %>"/>
<input type="hidden" name="data_id" value=""/>
</form>
<!--floater-->
<%@ include file="/admin/common/bottom.jsp" %>
<!--floater-->
</body>
</html>